package command;

import java.net.InetAddress;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.*;
import command.Command;
import command.CommandException;
import db.CommonConnect;

import common.CommonUtil;
import common.Crypto;
import common.EDUBOX_Baese64_Crypto;
import common.UserSession;
import db.QueryManager;
import db.DAO;

/**
 * Command 인터페이스를 implement 하여 구현된 command.
 */
public class RsmlModifyCommand extends Command {

	private String next;
	
	public RsmlModifyCommand(String next) {
		this.next=next;
	}

	/**
	 * 실제 요청을 받아 처리하는 메소드
	 * 요청을 받으면  요청을 처리하고 next 페이지를 돌려줌
	 * 
	 * @param req HttpServletRequest
	 * @throws CommandException
	 * @return next 이동할 페이지
	 */
	public String execute(HttpServletRequest req)
	throws CommandException {
		ArrayList list =  null;
		HashMap listMap = new HashMap();	
	
		Connection con = null;  
		try {		
					
			String rsml_eng_name = CommonUtil.nvl(req.getParameter("rsml_eng_name"));				
			String rsml_kor_name = CommonUtil.nvl(req.getParameter("rsml_kor_name"));
			
			String com_kor_cont = CommonUtil.nvl(req.getParameter("com_kor_cont"));
			String com_eng_cont = CommonUtil.nvl(req.getParameter("com_eng_cont"));
			
			String use_yn = CommonUtil.nvl(req.getParameter("use_yn"));
			String eng_yn = CommonUtil.nvl(req.getParameter("eng_yn"));
			String user_id = CommonUtil.nvl(req.getParameter("user_id"));			
			String sort = CommonUtil.nvl(req.getParameter("sort"));
			
			String rrg_code = CommonUtil.nvl(req.getParameter("rrg_code"));			
			String rsml_code = CommonUtil.nvl(req.getParameter("rsml_code"));
						
			con = (new CommonConnect()).getConnection_ds2();
			con.setAutoCommit(false);
			String[] param=null;
			String queryStr = "call sp_sp1002_modify(?,?,?,?,?,?,?,?,?)";
			param= new String[9];
			param[0] = rsml_code;
			param[1] = rsml_eng_name;
			param[2] = rsml_kor_name;
			param[3] = com_kor_cont;	
			param[4] = com_eng_cont;
			param[5] = use_yn;
			
			param[6] = user_id;
			param[7] = eng_yn;
			param[8] = sort;
			
			list = DAO.select(con,queryStr,param);
			
			listMap.put("mainContent",list);
			logger.debug("queryStr ==> "+"call sp_sp1002_modify(?,?,?,?,?,?,?,?,?)");		     
		     
// 리퀘스트에 모두 담는다.
			req.setAttribute("list_map",listMap);

		}catch (Exception ex) {
			try{
				con.rollback();
			}catch(Exception ee){}
			ex.printStackTrace();
			throw new CommandException(ex.getMessage());
		}finally {
			try{
				if (con!=null) con.setAutoCommit(true);
				if (con!=null) con.close();
			}catch(Exception ee){}
		}
		return next;
	}
	


}
